﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;
namespace ProjectM2Work
{
    public class GameMenuScreen : GameScreen
    {
        private Texture2D _background;
        private List<Button> _listMainButton;
        private GamePage _maingame;
#region  Initilation
        public GameMenuScreen(GamePage maingame,SpriteBatch spriteBatch, Texture2D background, List<Texture2D> listTextureMainButton)
            : base (maingame, spriteBatch)
        {
            _maingame = maingame;
            _spriteBatch = spriteBatch;
            _background = background;
            // Main button gom 3 nut home, about, exit
            _listMainButton = new List<Button>();
            //_listMainButton.Add(new Button(listTextureMainButton[1], new Vector2(70, 395)));
            //_listMainButton.Add(new Button(listTextureMainButton[2], new Vector2(30, 450)));
            _listMainButton.Add(new Button(listTextureMainButton[3], new Vector2(320, 190)));
            _listMainButton.Add(new Button(listTextureMainButton[4], new Vector2(570, 290)));

            for (int i = 0; i < _listMainButton.Count; i++)
            {
                _listMainButton[i].Selected += new Button.IsSelected(ButtonInGameMenuScreen_Selected);
            }
        }

        void ButtonInGameMenuScreen_Selected(int input)
        {
            switch (input)
            {
                //case 0: _maingame.GoToThongTin(); break;    // thong tin
                //case 1: _maingame.ShowBack(); break;    // thoat
                case 0: _maingame.ShowScreen(1); break;    // game truc xinh
                case 1: _maingame.GoToTracNghiem(); break;    // game trac nghiem
            }
        }

#endregion

#region Methods
        #region Update & Draw
        public override void OnUpdate(GameTimerEventArgs gameTime)
        {
            if (this.Enabled)
            {
                base.OnUpdate(gameTime);
                while (TouchPanel.IsGestureAvailable)
                {
                    GestureSample gesture = TouchPanel.ReadGesture();
                    switch (gesture.GestureType)
                    {
                        case GestureType.Tap:
                            {
                                for (int i = 0; i < _listMainButton.Count; i++)
                                    _listMainButton[i].ButtonIsTouched(gesture.Position, i);
                            }
                            break;
                        case GestureType.FreeDrag:
                            {
                            }
                            break;
                        case GestureType.DoubleTap:
                            {
                            }
                            break;
                        case GestureType.Pinch:
                            {
                            }
                            break;
                        case GestureType.DragComplete:
                            {
                            }
                            break;
                        default:
                            {

                            }
                            break;
                    }
                }
            }            
        }

        public override void OnDraw(GameTimerEventArgs gameTime)
        {
            if (this.Visible)
            {
                base.OnDraw(gameTime);
                _spriteBatch.Begin();
                _spriteBatch.Draw(_background, Vector2.Zero, Microsoft.Xna.Framework.Color.White);
                for (int i = 0; i < _listMainButton.Count; i++)
                    _listMainButton[i].Draw(_spriteBatch, gameTime);
                _spriteBatch.End();   
            }                  
        }
        
        #endregion
    }
#endregion
}
